<!doctype html>
<html><head>
	<meta charset="utf-8">
	<title>重新统计数据</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<!-- jQuery-->
	<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>
	
	<!-- layui-->
	<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all">
	<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>
	
	<!-- common -->
	<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
	<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />
	
	<!-- iconfont -->
	<link rel="stylesheet" href="/static/css/icon/iconfont.css" media="all" />

	<!-- 页面js
	<script type="text/javascript" src="/static/js/business/tpAmazonAnalysis/tpAmazonAnalysis.js?v=c"></script>
	-->
</head>
<body style="padding: 10px 0 0 10px;">
	<div style="width: 450px;margin: 0 auto ;margin-top: 50px;">
		<div class="layui-inline">
			<label class="layui-form-label" style="width: 200px;">请选择要重新统计的月份<span style="color: red;">*</span></label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input" id="ID-laydate-range-month" placeholder=" - ">
			</div>
		</div>
	</div>
	<!-- onclick="refreshCount();"-->
	<div style="width: 300px;margin: 0 auto ;margin-top: 120px;">
		<button type="button" id="sureBtn" class="layui-btn layui-btn-normal" style="width: 130px;">确定</button>
		<button type="button" class="layui-btn layui-btn-primary" style="width: 130px;"  onclick="noCount();">取消</button>
	</div>
	
	<script type="text/javascript">
		layui.use(function(){
			var nowTime = new Date();
			var yearNum = nowTime.getFullYear();
			var monthNum = nowTime.getMonth() + 1;
			var lastMonth = '';
			if(monthNum==1){
				lastMonth = (yearNum-1) + '-12';
			}else {
				var oldMonth = monthNum-1;
				lastMonth = yearNum + '-' + (oldMonth<10 ? '0'+oldMonth : oldMonth);
			}
			// 年月范围
			layui.laydate.render({
				elem: '#ID-laydate-range-month',
				type: 'month',
				//max: lastMonth,
				max: '2023-04',
				format:'yyyy-MM',
				value: lastMonth+' - '+lastMonth,
				range: true
			});
			var sureBtn = document.getElementById("sureBtn");//按钮id
			sureBtn.onclick = function () {
				var chooseMonth = $('#ID-laydate-range-month').val();
				if(chooseMonth==undefined || chooseMonth==null || chooseMonth==' - '|| chooseMonth==''){
					layer.msg("请先选择要重新统计的月份！", {icon: 0});
					return;
				}
				var chooseMonthMin = chooseMonth.split(' - ')[0].replace(/\s+/g,'');
				var chooseMonthMax = chooseMonth.split(' - ')[1].replace(/\s+/g,'');
				var warnInfo = '确定要重新统计从 '+chooseMonthMin+ ' 到 '+ chooseMonthMax + ' 的时效信息吗？';
				if(chooseMonthMin==chooseMonthMax){
					warnInfo = '确定要重新统计 ' +chooseMonthMin+ ' 的时效信息吗？';
				}
				layer.confirm(warnInfo, {icon: 3}, function () {
					//点击确定的回调
					layer.msg('重新统计中', {
						icon: 16,shade: 0.01
					});
					sureRefreshCount(chooseMonthMin,chooseMonthMax);
				}, function () {});
			}
		});
		/*
		function refreshCount(){
			var chooseMonth = $('#ID-laydate-range-month').val();
			var chooseMonthMin = chooseMonth.split(' - ')[0].replace(/\s+/g,'');
			var chooseMonthMax = chooseMonth.split(' - ')[1].replace(/\s+/g,'');
			var warnInfo = '确定要重新统计从 '+chooseMonthMin+ ' 到 '+ chooseMonthMax + ' 的时效信息吗？';
			if(chooseMonthMin==chooseMonthMax){
				warnInfo = '确定要重新统计 ' +chooseMonthMin+ ' 的时效信息吗？';
			}
			var layer = layui.layer;
			//var isSure = '';
			layer.confirm(warnInfo, {icon: 3}, function () {
				//点击确定的回调
				layer.msg('重新统计中', {
					icon: 16,shade: 0.01
				});
				sureRefreshCount(chooseMonthMin,chooseMonthMax);
			}, function () {});
		};

		 */
		function sureRefreshCount(chooseMonthMin,chooseMonthMax){

			$.ajax({
				url: '/web/business/tpTimeCheck/reSetTimeCheckData',
				data: {
					'chooseMonthMin':chooseMonthMin,
					'chooseMonthMax':chooseMonthMax
				},
				type: 'POST',
				async: true,
				success: function (result) {
					if(result.code=='0'){
						//layer.close();//关闭弹窗
						var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
						parent.layer.close(index);
						parent.location.reload();
						parent.layer.msg("重新统计成功", {icon: 1});
					}else {//失败
						layer.close();
						layer.msg("重新统计失败，请稍后再试！", {icon: 2});
					}
				},
				error: function () {
					layer.close();
					layer.msg("重新统计失败，请稍后再试！", {icon: 2});
				}
			});
		}
		//取消
		function noCount(){
			var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
			parent.layer.close(index);
		};

		$(function() {
			$('#id_panel_left_grid').css('height', (window.innerHeight - 140) + 'px');
		});
	</script>

</body>
		
</html>